﻿using System;
using System.Web;

namespace YN.Utils.Web
{
    public class UrlHelper
    {
        public static string GetStringUrlParam(string key)
        {
            return GetStringUrlParam(key, string.Empty);
        }
        public static string GetStringUrlParam(string key, string defaultValue)
        {
            return string.IsNullOrEmpty(HttpContext.Current.Request.QueryString[key]) ? defaultValue : HttpContext.Current.Request.QueryString[key];
        }

        public static int GetIntUrlParam(string key)
        {
            return GetIntUrlParam(key, 0);
        }
        public static int GetIntUrlParam(string key, int defaultValue)
        {
            string value = HttpContext.Current.Request.QueryString[key];

            return TypeConvert.StringToInt(value, defaultValue);
        }

        public static bool GetBoolUrlParam(string key)
        {
            return GetBoolUrlParam(key, false);
        }
        public static bool GetBoolUrlParam(string key, bool defaultValue)
        {
            string value = HttpContext.Current.Request.QueryString[key];

            return TypeConvert.StringToBool(value, defaultValue);
        }

        public static DateTime GetDateTimeUrlParam(string key)
        {
            return GetDateTimeUrlParam(key, DateTime.Now);
        }
        public static DateTime GetDateTimeUrlParam(string key, DateTime defaultValue)
        {
            string value = HttpContext.Current.Request.QueryString[key];

            return TypeConvert.StringToDateTime(value, defaultValue);
        }

    }
}
